package com.news.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.news.biz.News_DetailBiz;
import com.news.dao.News_CategoryDao;
import com.news.dao.News_DetailDao;
import com.news.entity.News_Category;
import com.news.entity.News_Detail;

/**
 * Servlet implementation class Initialize
 */
public class Initialize extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Initialize() {
        super();
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");

		News_DetailDao news_DetailDao =(News_DetailDao) context.getBean("news_DetailDao");
		News_CategoryDao news_CategoryDao=(News_CategoryDao) context.getBean("news_CategoryDao");
		List<News_Category> categories=news_CategoryDao.getAll();
		List<News_Detail> details =news_DetailDao.getAll();

		request.setAttribute("categories", categories);
		request.setAttribute("details", details);
		request.getRequestDispatcher("index.jsp").forward(request, response);
		
	}

}
